package org.csu.mypetstore.controller;

import com.alibaba.fastjson.JSONObject;
import jakarta.servlet.http.HttpSession;
import org.csu.mypetstore.aspect.LogAnnotation;
import org.csu.mypetstore.commonResponse.CommonResponse;
import org.csu.mypetstore.domin.Inventory;
import org.csu.mypetstore.domin.Item;
import org.csu.mypetstore.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/items")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @LogAnnotation(module="items",operation = "获得四个最火item")
    @GetMapping("/hot")
    public CommonResponse<List<Item>> getFourHot(){
        return itemService.fourHotItems();
    }
    //通过productid查看商品
    @LogAnnotation(module="items",operation = "通过productid查看商品")
    @GetMapping("/{productid}")
    public CommonResponse<JSONObject> getItemListByProduct(@PathVariable("productid") String productId){
        return itemService.getItemListByProduct(productId);
    }
     //通过itemid查看商品
     @LogAnnotation(module="items",operation = "通过itemid查看商品")
    @GetMapping("/product/{itemid}")
    public CommonResponse<Item> getItem(@PathVariable("itemid") String itemId){
        return itemService.getItem(itemId);
    }
}
